package com.lxq.www.pojo;



import com.lxq.www.enumeration.IdentityEnum;
import com.lxq.www.enumeration.SexEnum;
import com.lxq.www.enumeration.enumconverter.IdentityConverter;
import com.lxq.www.enumeration.enumconverter.SexConverter;

import javax.persistence.*;
import java.lang.reflect.Field;
import java.util.Date;

@Entity
@Table(name = "user")
public class User {

    @Id
    private String account;
    @Column
    private String username;
    @Column
    private String password;
    @Column(name = "createdate")
    private Date createDate;
    @Column
    @Convert(converter = SexConverter.class)
    private SexEnum sex;
    @Column
    @Convert(converter = IdentityConverter.class)
    private IdentityEnum identity;
    @Column
    private Date birthday;
    @Column
    private String portrait;

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public SexEnum getSex() {
        return sex;
    }

    public void setSex(SexEnum sex) {
        this.sex = sex;
    }

    public void setIdentity(IdentityEnum identity) {
        this.identity = identity;
    }

    public IdentityEnum getIdentity() {
        return identity;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getPortrait() {
        return portrait;
    }

    public void setPortrait(String portrait) {
        this.portrait = portrait;
    }

    public User convenience(String fieldName, Object fieldValue) {
        try {
            Field field = this.getClass().getDeclaredField(fieldName);
            field.setAccessible(true);
            field.set(this, fieldValue);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return this;
    }

    @Override
    public String toString() {
        return "User{" +
                "account='" + account + '\'' +
                ", userName='" + username + '\'' +
                ", password='" + password + '\'' +
                ", createDate=" + createDate +
                ", sex='" + sex.getSex() + '\'' +
                ", identity='" + identity.getRoleStr() + '\'' +
                ", birthday=" + birthday +
                ", portrait='" + portrait + '\'' +
                '}';
    }
}
